import Cookies from 'js-cookie'

const TokenKey = 'Token'

export function setToken(token) {
    Cookies.set(TokenKey, token)
}
export function getToken() {
    return Cookies.get(TokenKey)
}
export function removeToken() {
    Cookies.remove(TokenKey)
}

export function haveButtomMenu(menus, sign, b) {
    return menus.filter((menu) => {
        if (menu.type === '2' && menu.sign === sign) {
            b.boolean = false
        }else if (menu.children != null && menu.children && menu.children.length > 0) {
            haveButtomMenu(menu.children,sign, b)
        }
    })
}

export function buttomIsDisabled(router, key) {
    var sign = router.path + "-" + key
    let b = {'boolean': false}
    this.$store.getters.allButtomMenus.forEach(item => {
        if (item.sign === sign) {
            b.boolean = true
        }
    })
    if (b.boolean === false) {
        return false
    }
    haveButtomMenu(this.$store.getters.menus,sign, b)
    console.log(b.boolean)
    return b.boolean
}